package com.qkbb.admin.kuibu.qkbb.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qkbb.admin.kuibu.R;
import com.qkbb.admin.kuibu.adapter.PagerAdapter;
import com.qkbb.admin.kuibu.qkbb.JavaBean.Game;
import com.qkbb.admin.kuibu.qkbb.view.TitleBarView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by admin on 2016/1/25.
 */
public class Route_fragment extends Fragment {
    private View view;
    private ViewPager pager;
    public  List<Game> listbody;
    public  List<Game> listhead;
    private List<Recommend> list;
    private LinearLayout layout;
    private PagerAdapter pagerAdapter;
//    private int gamecategory;
//    private int page;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_route, null);

        init();
        pager();
        setonClick();
        return view;
    }
    public void setonClick(){
        layout.getChildAt(0).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(0);
            }
        });
        layout.getChildAt(1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(1);
            }
        });
        layout.getChildAt(2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(2);
            }
        });
        layout.getChildAt(3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(3);
            }
        });
        layout.getChildAt(4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(4);
            }
        }); layout.getChildAt(5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pager.setCurrentItem(5);
            }
        });


    }
    public void pager(){
                list=new ArrayList<Recommend>();
                for(int i=0;i<6;i++){
                    Recommend recommend=new Recommend();
                    recommend.setPostion(i);
                    list.add(recommend);
                }
            pagerAdapter=new PagerAdapter(getChildFragmentManager(),list);
            pager.setAdapter(pagerAdapter);

        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                Log.e("onPageScrolled", "" + position);
            }

            @Override
            public void onPageSelected(int position) {

                for (int i = 0; i < 6; i++) {
                    TextView textView1 = (TextView) layout.getChildAt(i);
                    textView1.setTextSize(15);
                }
                TextView textView = (TextView) layout.getChildAt(position);
                textView.setTextSize(17);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }
    public void init(){
        Log.e("111", "fragment");
        TitleBarView titleBarView= (TitleBarView) view.findViewById(R.id.route_titlebar);
        titleBarView.setCenterTexiView("跬步");
        titleBarView.setColor(R.color.touming);
        layout = (LinearLayout) view.findViewById(R.id.fragment_route_linearlayout);
            pager= (ViewPager) view.findViewById(R.id.route_viewpager);
    }
}
